<!DOCTYPE html>
<html>
<!--
Copyright 2011 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.

-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.graphics.SvgGraphics</title>
<script src="../base.js"></script>
<script>
  goog.require('goog.dom');
  goog.require('goog.graphics.SvgGraphics');
  goog.require('goog.testing.graphics');
  goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<div id="root"> </div>

<script>
  var graphics;

  function setUp() {
    if (!document.createElementNS) {
      // Some browsers don't support document.createElementNS and this test
      // should not be run on those browsers (IE7,8).
      return;
    }
    graphics = new goog.graphics.SvgGraphics('100px', '100px');
    graphics.createDom();
    goog.dom.getElement('root').appendChild(graphics.getElement());
  }

  function testAddDef() {
    if (!graphics) {
      // setUp has failed (no browser support), we should not run this test.
      return;
    }
    var defElement1 = document.createElement('div');
    var defElement2 = document.createElement('div');
    var defKey1 = 'def1';
    var defKey2 = 'def2';
    var id = graphics.addDef(defKey1, defElement1);
    assertEquals('_svgdef_0', id);
    id = graphics.addDef(defKey1, defElement2);
    assertEquals('_svgdef_0', id);
    id = graphics.addDef(defKey2, defElement2);
    assertEquals('_svgdef_1', id);
  }

  function testGetDef() {
    if (!graphics) {
      // setUp has failed (no browser support), we should not run this test.
      return;
    }
    var defElement = document.createElement('div');
    var defKey = 'def';
    var id = graphics.addDef(defKey, defElement);
    assertEquals(id, graphics.getDef(defKey));
    assertNull(graphics.getDef('randomKey'));
  }

  function testRemoveDef() {
    if (!graphics) {
      // setUp has failed (no browser support), we should not run this test.
      return;
    }
    var defElement = document.createElement('div');
    var defKey = 'def';
    var addedId = graphics.addDef(defKey, defElement);
    graphics.removeDef('randomKey');
    assertEquals(addedId, graphics.getDef(defKey));
    graphics.removeDef(defKey);
    assertNull(graphics.getDef(defKey));
  }
</script>
</body>
</html>

